import { useState,memo } from 'react';
import {
  MenuFoldOutlined,
  MenuUnfoldOutlined,
  UploadOutlined,
  UserOutlined,
  VideoCameraOutlined,
  RadarChartOutlined
} from '@ant-design/icons';
import { Button, Layout, Menu, theme,Space } from 'antd';
import { useNavigate, Outlet } from 'react-router-dom'
import homeStyle from './style.module.less';
const { Header, Sider, Content } = Layout;


const Home = () => {
  const [collapsed, setCollapsed] = useState(false);
  const {
    token: { colorBgContainer, borderRadiusLG },
  } = theme.useToken();
  const navigate = useNavigate()
  const menuClick = (route) => {
    const path = route.key
    navigate(path)
  }
    const handleRefresh = () => {
    window.location.reload()
  }
  return (
    <Layout hasSider>
      <Sider 
        trigger={null} 
        collapsible 
        collapsed={collapsed}
        className={homeStyle.sider}
        style={{
          overflow: 'auto',
          left: 0,
          top: 0,
          bottom: 0,
          zIndex: -1
        }}
      />
     <Sider
        trigger={null}
        collapsible
        collapsed={collapsed}
        className={homeStyle.sider}
        style={{
          overflow: 'auto',
          position: 'fixed',
          left: 0,
          top: 0,
          bottom: 0,
          zIndex: 10
        }}
      >
          
         <div className={homeStyle.headerIcon} onClick={handleRefresh}>
          {
            !collapsed ?
              (
                <Space align='baseline'>
                  烘丝机智能决策管理系统
                </Space>
              )
              : (<RadarChartOutlined />)
          }
        </div>
        <Menu
          onClick={(route) => menuClick(route)}
          className={homeStyle.menuStyle}
          theme="dark"
          mode="inline"
          // defaultSelectedKeys={['1']}
          items={[
            {
              key: '/',
              icon: <UserOutlined />,
              label: '参数设置',
            },
            {
              key: '/paramsprediction',
              icon: <VideoCameraOutlined />,
              label: '参数预测',
            },
            {
              key: '/trainmodel',
              icon: <UploadOutlined />,
              label: '模型重训',
            },
            {
              key: '/DataList',
              icon: <UploadOutlined />,
              label: '数据列表',
            },
          ]}
        />
      </Sider>
      <Layout>
        <Header
          style={{
            padding: 0,
            background: colorBgContainer,
          }}
        >
          <Button
            type="text"
            icon={collapsed ? <MenuUnfoldOutlined /> : <MenuFoldOutlined />}
            onClick={() => setCollapsed(!collapsed)}
            style={{
              fontSize: '16px',
              width: 64,
              height: 64,
            }}
          />
        </Header>
        <Content
          style={{
            margin: '24px 16px',
            padding: 24,
            minHeight: 280,
            background: colorBgContainer,
            borderRadius: borderRadiusLG,
          }}
        >
          <Outlet></Outlet>
        </Content>
      </Layout>
    </Layout>
  );
};
export const MemoHome = memo(Home)